using System.Collections.Generic;

using SharpGL.Media3D;

namespace SharpGL.SceneGraph.Helpers
{
	/// <summary>
	/// Helper class for point or vector search.
    /// </summary>
    public static class Media3DSearch
    {
        #region Public Methods

        public static int SearchPoint(IList<Point3D> points, int start, Point3D point, float accuracy)
        {
            //  Go through the verticies.
            for (int i = start; i < points.Count; i++)
            {
                if ((points[i].X >= (point.X - accuracy) && points[i].X <= (point.X + accuracy))
                    && (points[i].Y >= (point.Y - accuracy) && points[i].Y <= (point.Y + accuracy))
                    && (points[i].Z >= (point.Z - accuracy) && points[i].Z <= (point.Z + accuracy)))
                    return i;
            }

            return -1;
        }

        public static int SearchVector(IList<Vector3D> vectors, int start, Vector3D vector, float accuracy)
        {
            //  Go through the vectors.
            for (int i = start; i < vectors.Count; i++)
            {
                if ((vectors[i].X >= (vector.X - accuracy) && vectors[i].X <= (vector.X + accuracy))
                    && (vectors[i].Y >= (vector.Y - accuracy) && vectors[i].Y <= (vector.Y + accuracy))
                    && (vectors[i].Z >= (vector.Z - accuracy) && vectors[i].Z <= (vector.Z + accuracy)))
                    return i;
            }

            return -1;
        }

        #endregion Public Methods
    }
}
